package main

import (
	"fmt"
	"gitee.com/vrv_media/go-micro-framework/app"
	"gitee.com/vrv_media/go-micro-framework/example/config"
	"gitee.com/vrv_media/go-micro-framework/pkg/appcore"
	"gitee.com/vrv_media/go-micro-framework/pkg/common/util/fileutil"
	"gitee.com/vrv_media/go-micro-framework/pkg/logger"
	"gitee.com/vrv_media/go-micro-framework/server/restserver"
	"github.com/gin-gonic/gin"
)

var configOptions = config.NewConfig()

func main() {

	appcore.NewCoreApp("hello_test", "test",
		appcore.WithOptions(configOptions),
		appcore.WithRunFunc(run),
	).Run()
}
func run(basename string) error {

	logger.Init(configOptions.Log)
	currentDirectory := fileutil.GetCurrentDirectory()
	addr := fmt.Sprintf("%s:%d", "0.0.0.0", 4443)
	server := restserver.NewServer(
		restserver.WithAddress(addr),
		restserver.WithTLSConfig(currentDirectory+"/certs/fullchain.pem", currentDirectory+"/certs/privkey.key"),
	)
	server.Engine.GET("/test", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"code": 200,
			"msg":  "hello",
		})
	})
	// 创建server app并启动
	err := app.New(app.WithServer(server)).Run()
	if err != nil {
		panic(err)
	}
	return nil
}
